<template>
  <div id="app">
    <el-container class="container">
      <el-aside width="200px">
        <el-row class="tac">
          <el-col>
            <el-menu
              :default-active="active"
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#ffd04b"
              class="el-menu-vertical-demo"
              @select="handleSelect">
              <el-menu-item index="add">
                <i class="el-icon-plus"></i>
                <span slot="title">添加货品</span>
              </el-menu-item>
              <el-menu-item index="list">
                <i class="el-icon-document"></i>
                <span slot="title">货品列表</span>
              </el-menu-item>
              <el-menu-item index="goodsmap">
                <i class="el-icon-picture-outline"></i>
                <span slot="title">货品地图</span>
              </el-menu-item>
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>
      <el-main>
        <router-view/>
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'App',
  data () {
    return {
      active: 'list'
    }
  },
  methods: {
    handleSelect (key, keyPath) {
      // console.log(key, keyPath)
      this.$router.push({ path: key })
    },
    upActive () {
      // console.log(this.$route.name)
      this.active = this.$route.name
    }
  },
  // 组件加载之前
  created () {
    this.$Variable.userLogin()
    this.active = this.$route.name
  },
  // 监听路由变化
  watch: {
    // 如果路由有变化，会再次执行该方法
    '$route': 'upActive'
  }
}
</script>

<style lang="scss">
#app {
  height: 100%;
}
.container {
  height: 100%;
  .el-aside {
    background-color: #545c64;
  }
  .el-menu-vertical-demo {
    border: none;
  }
}
</style>
